class Node(object):
    """链表的节点"""
    def __init__(self, item):
        self.item = item
        self.next:Node = None
        self.back:Node = None

class LinkList(object):
    def __init__(self):
        self.head:Node = None

    def is_empty(self):
        return self.head is None

    def add(self, node:Node, nextNode:Node|None=None):
        """添加链表元素
        -----
        * node：添加的元素
        * next：指向的元素,None就是在尾部添加元素"""

        if nextNode is not None:
            node.next = nextNode
            node.back = nextNode.back
            try:
                nextNode.back.next = node
            except:
                pass
            nextNode.back = node
        else:
            node.next = self.head
            try:
                self.head.back = node
            except:
                pass
            self.head = node
            
    def remove(self, node:Node):
        """删除链表元素"""
        node.next.back = node.back
        node.back.next = node.next

    def travel(self):
        point = self.head
        while point is not None:
            print(point.item,end='')
            point = point.next


if __name__ == '__main__':
    llst = LinkList()
    node1 = Node(1)
    node2 = Node(3)
    node3 = Node(5)

    llst.add(node3)
    llst.add(node1)
    llst.add(node2,node3)

    llst.travel()
    